package org.liuyunfeng.web;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.liuyunfeng.SourceCodeReadApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author: TanJingyu
 * @create: 2022-08-17 17:05
 **/
@RestController
@RequestMapping("/init")
public class InitController {
//    private SourceCodeReadApplication.Demo<String> demo;
    @Autowired
    private ObjectMapper objectMapper;

    @PostMapping("/upload")
    public void upload(MultipartHttpServletRequest request) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    }

    @GetMapping("/long")
    public Object longTest(Long t) {
        System.out.println(t);
        return new LongDemo(1234567898765432101L);
    }

    public static class LongDemo {
        @JsonSerialize
        private Long l;

        public LongDemo() {
        }

        public LongDemo(Long l) {
            this.l = l;
        }

        public Long getL() {
            return l;
        }

        public void setL(Long l) {
            this.l = l;
        }
    }


    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {

//        SourceCodeReadApplication.Demo<Object> objectDemo = new SourceCodeReadApplication.Demo<>();
//
//        InitController initController = new InitController();
//        Field demo = initController.getClass().getDeclaredField("demo");
//        demo.set(initController, objectDemo);
//
//        System.out.println(demo);

//        System.out.println("\\$");
//        System.out.println("\\6");

        LongDemo longDemo = new LongDemo(1234567898765432101L);
        System.out.println(new ObjectMapper().writeValueAsString(longDemo));

    }
}

    